package com.sxm.yiwei.tools;

import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.sxm.yiwei.R;
import com.sxm.yiwei.activitis.AppManager;
import com.sxm.yiwei.activitis.CryActivity;
import com.sxm.yiwei.activitis.MineAccount;
import com.sxm.yiwei.activitis.UserLoginActivity;
import com.sxm.yiwei.utils.BookStateChangeUtils;

/**
 * Created by KuKa on 2017/9/16.
 * 判断是否注册登陆
 *
 */

public class IsLogin {

    private static AlertDialog.Builder builder;

    public static boolean isLogin(){

        boolean userState;
        BookStateChangeUtils bookStateChangeUtils = new BookStateChangeUtils();
        bookStateChangeUtils.getParameter();
        if (bookStateChangeUtils.token.equals("")){
            userState=false;
            builder =  new AlertDialog.Builder(AppManager.getAppManager().currentActivity());
            View view = LayoutInflater.from(AppManager.getAppManager().currentActivity()).inflate(R.layout.amount_dialog, null);
            builder.setView(view);
            Button cancel = (Button) view.findViewById(R.id.amount_cancel);
            Button sure = (Button) view.findViewById(R.id.amount_sure);
            TextView message = (TextView) view.findViewById(R.id.amount_message);
            TextView title = (TextView) view.findViewById(R.id.amount_title);
            title.setText("提示");
            message.setText("您还没有注册或登录,是否前往？");
            cancel.setText("否");
            sure.setText("是");
            final AlertDialog dialog = builder.create();
            cancel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                }
            });
            sure.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    AppManager.getAppManager().currentActivity().startActivity(new Intent(AppManager.getAppManager().currentActivity(),UserLoginActivity.class));
                    AppManager.getAppManager().currentActivity().finish();
                }
            });
            dialog.show();

        }else {// 已登陆
         userState = true;
        }
        return userState;

    }
}
